# -*- coding: utf-8 -*-
from flask import Flask
import click
from flask_sqlalchemy import SQLAlchemy
import os
import datetime
class Application( Flask ):
    def __init__(self,import_name , template_folder = None,root_path = None ):
        super( Application,self ).__init__( import_name ,template_folder = template_folder,root_path = root_path,static_folder = None)
        self.config.from_pyfile( 'config/base_setting.py' )
        if "ops_config" in os.environ:
            self.config.from_pyfile( 'config/%s_setting.py'%os.environ['ops_config'] )

        db.init_app(self)
        
        # 设置时区为中国标准时间
        import pytz
        self.config['TIMEZONE'] = 'Asia/Shanghai'

        # 注册自定义启动命令
        @self.cli.command("runserver")
        @click.option('--host', default='0.0.0.0', help='主机地址')
        @click.option('--port', default=8999, help='端口号')
        def runserver(host, port):
            self.run(host=host, port=port, debug=True)

db = SQLAlchemy()
app = Application(__name__, template_folder=os.getcwd()+"/web/templates/", root_path=os.getcwd())

'''
函数模板
'''
from common.libs.UrlManager import UrlManager
app.add_template_global(UrlManager.buildStaticUrl, 'buildStaticUrl')
app.add_template_global(UrlManager.buildUrl, 'buildUrl')
app.add_template_global(UrlManager.buildImageUrl, 'buildImageUrl')


